package com.ruoyi.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Hitch;
import com.ruoyi.system.service.IHitchService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 故障上报 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-07
 */
@Api("故障上报管理")
@Controller
@RequestMapping("/system/hitch")
public class HitchController extends BaseController
{
    private String prefix = "system/hitch";
	
	@Autowired
	private IHitchService hitchService;
	
	@RequiresPermissions("system:hitch:view")
	@GetMapping()
	public String hitch()
	{
	    return prefix + "/hitch";
	}
	
	/**
	 * 查询故障上报列表
	 */
	@ApiOperation("查询故障上报列表")
	@RequiresPermissions("system:hitch:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Hitch hitch)
	{
		startPage();
        List<Hitch> list = hitchService.selectHitchList(hitch);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出故障上报列表
	 */
	@RequiresPermissions("system:hitch:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Hitch hitch)
    {
    	List<Hitch> list = hitchService.selectHitchList(hitch);
        ExcelUtil<Hitch> util = new ExcelUtil<Hitch>(Hitch.class);
        return util.exportExcel(list, "hitch");
    }
	
	/**
	 * 新增故障上报
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存故障上报
	 */
	@ApiOperation("新增保存故障上报")
	@RequiresPermissions("system:hitch:add")
	@Log(title = "故障上报", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Hitch hitch)
	{		
		return toAjax(hitchService.insertHitch(hitch));
	}

	/**
	 * 修改故障上报
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		Hitch hitch = hitchService.selectHitchById(id);
		mmap.put("hitch", hitch);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存故障上报
	 */
	@ApiOperation("修改保存故障上报")
	@RequiresPermissions("system:hitch:edit")
	@Log(title = "故障上报", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Hitch hitch)
	{		
		return toAjax(hitchService.updateHitch(hitch));
	}
	
	/**
	 * 删除故障上报
	 */
	@ApiOperation("删除故障上报")
	@RequiresPermissions("system:hitch:remove")
	@Log(title = "故障上报", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(hitchService.deleteHitchByIds(ids));
	}
	
}
